<template>
  <BgVue4 class="staticRecord">
    <template #imgFixed>
      <img src="@/assets/imgV2/exchange-bg-bottom.jpg" />
    </template>
    <div class="title-style title">{{ t('withdraw.TQJL') }}</div>
    <div class="block-bor" v-for="(item, index) in list" :key="index">
      <BoxView2>
        <div class="block-item-head">
          <van-cell :border="false">
            <template #title>
              <div class="text">{{ t('withdraw.TXLX') }}</div>
            </template>
            <template #value>
              <div class="text-right">{{ item.type }}</div>
            </template>
          </van-cell>
          <van-cell :border="false">
            <template #title>
              <div class="text">{{ t('withdraw.TS') }}</div>
            </template>
            <template #value>
              <div class="text-right">{{ item.num }}</div>
            </template>
          </van-cell>
          <van-cell :border="false">
            <template #title>
              <div class="text">{{ item.time }}</div>
            </template>
            <template #value>
              <div class="text-right">
                <span class="col-grey">{{ item.statusStr }}</span>
                <span
                  class="col-yellow"
                  @click="cancel(item)"
                  v-if="item.status === 0"
                  >{{ t('common.cancelText') }}</span
                >
              </div>
            </template>
          </van-cell>
          <template v-if="item.remark">
            <div class="bor"></div>
            <van-cell :border="false">
              <template #title>
                <div class="marT text-right col-grey">{{ item.remark }}</div>
              </template>
            </van-cell>
          </template>
        </div>
      </BoxView2>
    </div>
  </BgVue4>
</template>
<script>
import http from '../http'
import BoxView2 from '@/components/BoxView2.vue'
import BgVue4 from '@/components/BgVue4.vue'

export default {
  data() {
    return {
      list: [],
    }
  },
  mounted() {
    this.init()
  },
  methods: {
    async init() {
      const coinIds = {
        PT: 1,
        PLAY: 2,
      }
      const coin = this.$route.query.coin
      var coinId = coinIds[coin]
      if (coinId) {
        const res = await http.get(`/api/user/coinLog?type=1&coinId=${coinId}`)
        if (res.code === 200) {
          const statusMap = [
            '等待提现',
            '提现中',
            '提现成功',
            '已撤销',
            '已撤销',
          ]
          this.list = res.data?.map((row) => {
            return {
              id: row.id,
              type: coin,
              num: row.amount,
              time: row.create_time.substr(0, 16).replace('T', ' '),
              statusStr: statusMap[row.status],
              status: row.status,
              // remark: "撤销备注：暂停提现功能"
            }
          })
          // if (process.env.NODE_ENV !== 'production') {
          //   this.list = [
          //     {
          //       id: 'row.id,',
          //       type: 'coin,',
          //       num: 'row.amount,',
          //       time: '2020-2-2 00:00:00',
          //       statusStr: '成功',
          //       status: 'row.status,',
          //     },
          //   ]
          // }
        }
      }
    },
    async cancel(row) {
      const res = await http.post(`/api/user/cancelWithdraw?id=${row.id}`)
      if (res.code === 200) {
        Toast('取消成功')
      }
      this.init()
    },
  },
  components: { BoxView2, BgVue4 },
}
</script>
<style lang="less" scoped>
.staticRecord {
  text-align: left;

  .title {
    // position: relative;
    // display: inline-block;
    padding: 10px 0 0;
    // margin: 14px 15px 5px 15px;
    // color: #ffffff;
    font-size: 22px;
    text-align: center;
    // font-weight: 400;
  }

  // .title::after {
  //   position: absolute;
  //   left: 50%;
  //   bottom: 0;
  //   display: block;
  //   width: 50px;
  //   height: 2px;
  //   background: #e7a20d;
  //   content: '';
  //   transform: translateX(-50%);
  // }

  .van-cell {
    align-items: center;
    height: 30px;
    padding: 0 15px;
    background: transparent;
  }

  .text {
    color: #fff;
    font-size: 14px;
    line-height: 20px;
  }

  .text-right {
    color: #f7cc40;
    font-size: 13px;
    line-height: 18px;
  }

  .col-yellow {
    position: relative;
    color: #f9a614;
    padding-left: 16px;
  }

  .col-yellow::before {
    position: absolute;
    left: 8px;
    top: 50%;
    z-index: 2222222;
    display: block;
    width: 1px;
    height: 12px;
    background: #f9a614;
    content: '';
    transform: translateY(-50%);
  }

  .bor {
    height: 1px;
    background: #333036;
    margin-top: 9px;
  }

  .marT {
    margin-top: 15px;
  }
}
</style>
